package com.fanshilz.flower2025.apps.admin.more.controller;

import com.fanshilz.flower2025.apps.admin.more.req.ProjectMoreTableReq;
import com.fanshilz.flower2025.apps.admin.more.resp.ProjectMoreTableDetailResp;
import com.fanshilz.flower2025.business.flower.projectMore.service.IProjectMoreService;
import com.fanshilz.flower2025.framework.resp.Resp;
import com.fanshilz.flower2025.framework.resp.TableResp;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/more")
public class MoreController {

    @Resource
    private IProjectMoreService projectMoreService;

    @PostMapping("/table")
    public Resp<TableResp<ProjectMoreTableDetailResp>> table(@RequestBody @Valid ProjectMoreTableReq req) {
        QueryWrapper qw = QueryWrapper.create();
        Page<ProjectMoreTableDetailResp> page = projectMoreService.getMapper()
                .paginateWithRelationsAs(Page.of(req.getCurrent(), req.getPageSize(), req.getTotal()), qw, ProjectMoreTableDetailResp.class);
        return Resp.success(new TableResp<>(page.getRecords(), page.getTotalRow()));
    }

}
